﻿using BG.DAL.Model;
using BG.DAL.Context;
using System.Collections.Generic;
using System;
using System.Data;
using System.Data.Entity;
using System.Linq;

namespace BG.DAL.SQLDAL
{
    public class ManufacturerManager
    {
        public static Manufacturer GetById(Guid id)
        {
            using (DataContext db = new DataContext())
            {
                Manufacturer Model = db.Manufacturers.Find(id);
                return Model;
            }
        }

        public static List<Manufacturer> GetAll()
        {
            using (DataContext db = new DataContext())
            {
                var i = db.Manufacturers.ToList();
                return i;
            }
        }

        public static List<Manufacturer> GetByFilter(string text)
        {
            using (DataContext db = new DataContext())
            {
                return db.Manufacturers.Where(m => m.sManufacturerName.Equals(text)).ToList();
            }
        }

        public static void Create(Manufacturer model)
        {
            using (DataContext db = new DataContext())
            {
                db.Manufacturers.Add(model);
                db.SaveChanges();
            }
        }

        public static void Edit(Manufacturer model)
        {
            using (DataContext db = new DataContext())
            {
                db.Entry(model).State = EntityState.Modified;
                db.SaveChanges();
            }
        }

        public static void Delete(Guid id)
        {
            using (DataContext db = new DataContext())
            {
                Manufacturer model = db.Manufacturers.Find(id);
                db.Manufacturers.Remove(model);
                db.SaveChanges();

            }
        }


    }
}
